package io.github.biezhi.factory.abstractFactory;

// 定义颜色接口
interface Color {
    void fill();
}

// 具体颜色类：Red 和 Blue
class Red implements Color {
    @Override
    public void fill() {
        System.out.println("Filling with red color");
    }
}

class Blue implements Color {
    @Override
    public void fill() {
        System.out.println("Filling with blue color");
    }
}

// 定义形状接口
interface Shape {
    void draw();
}

// 具体形状类：Circle 和 Square
class Circle implements Shape {
    @Override
    public void draw() {
        System.out.println("Drawing a circle");
    }
}

class Square implements Shape {
    @Override
    public void draw() {
        System.out.println("Drawing a square");
    }
}

// 抽象工厂接口
interface AbstractFactory {
    Color getColor(String colorType);
    Shape getShape(String shapeType);
}

// 具体工厂类：RedShapeFactory 和 BlueShapeFactory
class RedShapeFactory implements AbstractFactory {
    @Override
    public Color getColor(String colorType) {
        if ("red".equalsIgnoreCase(colorType)) {
            return new Red();
        } else {
            throw new IllegalArgumentException("Invalid color type");
        }
    }

    @Override
    public Shape getShape(String shapeType) {
        if ("circle".equalsIgnoreCase(shapeType)) {
            return new Circle();
        } else if ("square".equalsIgnoreCase(shapeType)) {
            return new Square();
        } else {
            throw new IllegalArgumentException("Invalid shape type");
        }
    }
}

class BlueShapeFactory implements AbstractFactory {
    @Override
    public Color getColor(String colorType) {
        return null;
    }

    @Override
    public Shape getShape(String shapeType) {
        return null;
    }
    // 实现类似 RedShapeFactory，返回对应颜色和形状的蓝色版本
}

// 客户端使用
public class AbstractFactory3 {
    public static void main(String[] args) {
        AbstractFactory redFactory = new RedShapeFactory();
        Shape redCircle = redFactory.getShape("circle");
        redCircle.draw();
        Color redColor = redFactory.getColor("red");
        redColor.fill();

        AbstractFactory blueFactory = new BlueShapeFactory();
        // 使用 blueFactory 创建并操作蓝色形状和颜色
    }
}

